/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.autoconfigure.context;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.springframework.boot.convert.DurationUnit;

/**
 * 消息源的配置属性。
 *
 * @author Stephane Nicoll
 * @author Kedar Joshi
 * @since 2.0.0
 */
public class MessageSourceProperties {

	/**
	 * 以逗号分隔的基名称列表（本质上是完全限定的类路径位置），
	 * 每个名称遵循 ResourceBundle 约定，支持使用斜杠的宽松位置表示法。
	 * 如果不包含包限定符（如 "org.mypackage"），则从类路径根解析。
	 */
	private String basename = "messages";

	/**
	 * 消息资源文件的编码。
	 */
	private Charset encoding = StandardCharsets.UTF_8;

	/**
	 * 已加载资源包文件的缓存时长。未设置时，资源包将永久缓存。
	 * 如果未指定时长单位后缀，则默认以秒为单位。
	 */
	@DurationUnit(ChronoUnit.SECONDS)
	private Duration cacheDuration;

	/**
	 * 如果未找到特定 Locale 的文件，是否回退到系统 Locale。
	 * 关闭时，唯一回退为默认文件（例如 basename 为 "messages" 时的 "messages.properties"）。
	 */
	private boolean fallbackToSystemLocale = true;

	/**
	 * 是否总是应用 MessageFormat 规则，即使消息无参数也解析。
	 */
	private boolean alwaysUseMessageFormat = false;

	/**
	 * 是否使用消息代码作为默认消息，而非抛出 "NoSuchMessageException"。
	 * 建议仅在开发阶段启用。
	 */
	private boolean useCodeAsDefaultMessage = false;

	public String getBasename() {
		return this.basename;
	}

	public void setBasename(String basename) {
		this.basename = basename;
	}

	public Charset getEncoding() {
		return this.encoding;
	}

	public void setEncoding(Charset encoding) {
		this.encoding = encoding;
	}

	public Duration getCacheDuration() {
		return this.cacheDuration;
	}

	public void setCacheDuration(Duration cacheDuration) {
		this.cacheDuration = cacheDuration;
	}

	public boolean isFallbackToSystemLocale() {
		return this.fallbackToSystemLocale;
	}

	public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) {
		this.fallbackToSystemLocale = fallbackToSystemLocale;
	}

	public boolean isAlwaysUseMessageFormat() {
		return this.alwaysUseMessageFormat;
	}

	public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) {
		this.alwaysUseMessageFormat = alwaysUseMessageFormat;
	}

	public boolean isUseCodeAsDefaultMessage() {
		return this.useCodeAsDefaultMessage;
	}

	public void setUseCodeAsDefaultMessage(boolean useCodeAsDefaultMessage) {
		this.useCodeAsDefaultMessage = useCodeAsDefaultMessage;
	}

}
